- /* simcv2bn.cpp by K.Tsuru */
- // function ID = 402 BRADIX
- /****************************************************
- SInteger class
- It provides the radix conversion SLong to SInteger.
- *****************************************************/
- #ifndef SN_H
- #include "sn.h"
- #endif
- SInteger SInteger::NConvToBin(const SLong& m){
- SInteger result;
- uint szD = m.Head()+1u;
- if(szD <= 2){ //m has two or under figures. including the case m=0.
- long v = (long)m[1]*DRADIX + (long)m[0];
- if(m.Sign() < 0) v = -v;
- result.SetLong(v);
- return result;
- }
- // m != 0
- uint szB = uint( szD*( log10((double)DRADIX)/log10((double)BRADIX) ) )+ 1u; // ver. 2.17
- result.FigureAlloc(szB, 0);
- int h = m.Head(), j = (int)h - 1;
- const fType* mv = m.ReadFigures();
-
- result.SetLong((long)mv[h]); //It sets the top figure. result > 0
-
- while(j >= 0){
- IsMult(result, DRADIX, result); //result*=DRADIX;
- //It is faster than IIAdd() by a ratio 1.4.
- IsAdd(result, mv[j], result); //result+=mv[j];
- j--;
- }
-
- result.SetSign(m.Sign());
- result.CutDown(result.POP);
- if( 2u*(result.aHead+1) <= result.figure.size() ) result.DoCutDown();
- return result;
- }
-
- SInteger SInteger::ConvToBin(const SLong& m){
- if(m.Type() == m.BIN_INT){
- SInteger r;
- r.CopyValue(m, r.COPY); return r;
- }
- // Head()+1 =< iNconvBinMaxFig : BSConvToBin() is faster than NConvTodec()
- SInteger result;
- if(m.Head()+1 <= iNconvBinMaxFig) result = NConvToBin(m);
- else result = BSConvToBin(m); // ver.2.17
- return result;
- }
-
simcv2bn.cpp : last modifiled at 2017/03/13 14:31:59(1,527 bytes)
created at 2016/04/25 14:53:17
The creation time of this html file is 2017/10/25 11:09:45 (Wed Oct 25 11:09:45 2017).